<template>
  <el-dialog
    append-to-body
    :destroy-on-close="true"
    :title="title"
    :visible.sync="dialogFormVisible"
    width="500px"
    @close="close"
  >
    <el-form ref="form" label-width="80px" :model="form">
      <el-form-item label="模板代码" prop="template_code">
        <el-input v-model="form.template_code" />
      </el-form-item>
      <el-form-item label="模板标题" prop="template_title">
        <el-input v-model="form.template_title" />
      </el-form-item>
      <el-form-item label="模板内容" prop="template_content">
        <el-input v-model="form.template_content" rows="5" type="textarea" />
      </el-form-item>
      <el-form-item label="签名" prop="sign_name">
        <el-input v-model="form.sign_name" />
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-switch
          v-model="form.status"
          active-text="显示"
          :active-value="1"
          inactive-text="隐藏"
          :inactive-value="0"
        />
      </el-form-item>
    </el-form>
    <template #footer>
      <el-button @click="close">取 消</el-button>
      <el-button type="primary" @click="save">确 定</el-button>
    </template>
  </el-dialog>
</template>

<script>
  import { editTplList } from '@/api/message'

  export default {
    name: 'MessageEditDetail',
    data() {
      return {
        form: {},
        title: '编辑',
        dialogFormVisible: false,
        list: [],
        userList: [],
      }
    },
    methods: {
      showEdit(row) {
        console.log(row)
        this.form = Object.assign({}, row)
        this.form.template_id = row.id
        this.form.status = row.template_status
        this.dialogFormVisible = true
        this.$forceUpdate()
      },

      close() {
        this.$refs['form'].resetFields()
        this.form = this.$options.data().form
        this.dialogFormVisible = false
      },
      async save() {
        const { data } = await editTplList(this.form)
        if (data.is_success) {
          this.$baseMessage('修改成功', 'success', 'vab-hey-message-success')
          this.$emit('fetch-data')
        }
        this.close()
      },
    },
  }
</script>
